package top.codedance.iotp.server.net.handle.configuration;

import top.codedance.iotp.server.net.handle.subhandle.controller.Controller;
import top.codedance.iotp.server.net.handle.subhandle.controller.http.sync.*;

import java.util.HashMap;
import java.util.Map;

public class HttpRouteConfig {
    private static final String CONTENT_PATH = "/rest/api";

    public static Map<String, Controller> getConfig(){
        HashMap<String, Controller> routeConfig = new HashMap<>();

        /**
         * 获取服务端信息接口
         * request:
         *    {
         *     "username": "xuedianfu",
         *     "password": "123456"
         * }
         *
         *  response:
         *     {
         *     "data": {
         *         "dataVersion": 0,
         *         "sessionCount": 0
         *     },
         *     "message": "",
         *     "status": 200
         * }
         */
        routeConfig.put(CONTENT_PATH + "/server/information", new InformationController());

        /**
         * 获取所有客户端注册的deviceId
         * request:
         *    {
         *     "username": "xuedianfu",
         *     "password": "123456"
         * }
         * response:
         *     {
         *     "data": [
         *         "testDeviceId"
         *     ],
         *     "message": "",
         *     "status": 200
         * }
         */
        routeConfig.put(CONTENT_PATH + "/server/registed/deviceIds", new RegistedClientsController());

        /**
         * 添加合法设备
         * request:
         *   {
         *     "username": "xuedianfu",
         *     "password": "123456",
         *     "devices": [
         *         {
         *             "deviceId": "testDeviceId2",
         *             "unitName": "测试"
         *         },
         *         {
         *             "deviceId": "testDeviceId3",
         *             "unitName": "测试"
         *         }
         *     ]
         * }
         * response:
         *   {
         *     "data": "Add success",
         *     "message": "",
         *     "status": 200
         * }
         */
        routeConfig.put(CONTENT_PATH + "/server/device/add", new DeviceAddController());

        /**
         * 删除设备
         * request:
         *   {
         *     "username": "xuedianfu",
         *     "password": "123456",
         *     "id": "3"
         * }
         * response:
         *   {
         *     "data": "Delete success",
         *     "message": "",
         *     "status": 200
         * }
         */
        routeConfig.put(CONTENT_PATH + "/server/device/delete", new DeviceDeleteController());

        /**
         * 查询所有合法设备
         * request:
         *  {
         *     "username": "xuedianfu",
         *     "password": "123456"
         * }
         * response:
         *  {
         *     "data": [
         *         {
         *             "deviceId": "testDeviceId",
         *             "id": 2,
         *             "registeTime": "Mon Apr 12 09:54:13 CST 2021",
         *             "unitName": "测试"
         *         }
         *     ],
         *     "message": "",
         *     "status": 200
         * }
         */
        routeConfig.put(CONTENT_PATH + "/server/device/list", new DeviceListController());

        /**
         * 添加用户
         * request:
         *   {
         *     "username": "xuedianfu",
         *     "password": "123456",
         *     "users": [
         *         {
         *             "deviceId": "testDeviceId1",
         *             "username": "xuedianfu1",
         *             "isAdmin" : 0,
         *             "password": "123456"
         *         },
         *         {
         *             "deviceId": "testDeviceId2",
         *             "username": "xuedianfu2",
         *             "isAdmin" : 0,
         *             "password": "123456"
         *         }
         *     ]
         * }
         * response:
         *   {
         *     "data": "Add success",
         *     "message": "",
         *     "status": 200
         * }
         */
        routeConfig.put(CONTENT_PATH + "/server/user/add", new UserAddController());

        /**
         * 删除用户
         * request:
         *   {
         *     "username": "xuedianfu",
         *     "password": "123456",
         *     "id": "3"
         * }
         * response:
         *   {
         *     "data": "Delete success",
         *     "message": "",
         *     "status": 200
         * }
         */
        routeConfig.put(CONTENT_PATH + "/server/user/delete", new UserDeleteController());

        /**
         * 查询所有用户
         * request:
         *   {
         *     "username": "xuedianfu",
         *     "password": "123456"
         * }
         * response:
         *   {
         *     "data": [
         *         {
         *             "deviceId": "testDeviceId2",
         *             "id": 3,
         *             "password": "123456",
         *             "username": "xuedianfu2"
         *         },
         *         {
         *             "deviceId": "testDeviceId1",
         *             "id": 2,
         *             "password": "123456",
         *             "username": "xuedianfu1"
         *         },
         *         {
         *             "deviceId": "testDeviceId",
         *             "id": 1,
         *             "password": "123456",
         *             "username": "xuedianfu"
         *         }
         *     ],
         *     "message": "",
         *     "status": 200
         * }
         */
        routeConfig.put(CONTENT_PATH + "/server/user/list", new UserListController());

        /**
         * 设置客户端最新版本号
         * request:
         *   {
         *     "username": "xuedianfu",
         *     "password": "123456",
         *     "versionCode": 3
         * }
         * response:
         *   {
         *     "data": "Set success, current last version code: 3",
         *     "message": "",
         *     "status": 200
         * }
         */
        routeConfig.put(CONTENT_PATH + "/server/client/version/set", new ClientVersionController());

        /**
         * 设置客户端各插件参数
         * request:
         *   {
         *     "username": "xuedianfu",
         *     "password": "123456",
         *     "deviceId": "d1",
         *     "params": {
         *          "mysql": {
         *              "jdbcUrl": "jdbc:mysql://10.229.40.252:3306/epsdb?characterEncoding=UTF-8&serverTimezone=GMT%2B8",
         *              "user": "root_s",
         *              "password": "root@s"
         *          },
         *          "mssql": {
         *              "jdbcUrl": "jdbc:sqlserver://10.229.40.252:3306;databaseName=epsdb",
         *              "user": "root_s",
         *              "password": "root@s"
         *          }
         *     }
         * }
         * response:
         *   {
         *     "data": "success",
         *     "message": "Success",
         *     "status": 200
         * }
         */
        routeConfig.put(CONTENT_PATH + "/client/plugins/params/set", new SetClientPluginsParamsController());

        /**
         * 获取客户端各插件参数
         * request:
         *   {
         *     "username": "xuedianfu",
         *     "password": "123456",
         *     "deviceId": "d1"
         * }
         * response:
         *   {
         *     "data": "success",
         *     "message": "参数内容",
         *     "status": 200
         * }
         */
        routeConfig.put(CONTENT_PATH + "/client/plugins/params/get", new GetClientPluginsParamsController());

        /**
         * 设置客户端服务启动参数
         * request:
         *   {
         *     "username": "xuedianfu",
         *     "password": "123456",
         *     "deviceId": "d1",
         *     "params": "参数内容"
         * }
         * response:
         *   {
         *     "data": "success",
         *     "message": "Success",
         *     "status": 200
         * }
         */
        routeConfig.put(CONTENT_PATH + "/client/boot/params/set", new SetClientBootParamsController());

        /**
         * 获取客户端服务启动参数
         * request:
         *   {
         *     "username": "xuedianfu",
         *     "password": "123456",
         *     "deviceId": "d1"
         * }
         * response:
         *   {
         *     "data": "success",
         *     "message": "参数内容",
         *     "status": 200
         * }
         */
        routeConfig.put(CONTENT_PATH + "/client/boot/params/get", new GetClientBootParamsController());

        /**
         * 通过Generic DB SQL语句查询数据库
         * request:
         *  {
         *     "username": "xuedianfu",
         *     "password": "123456",
         *     "deviceId": "d1",
         *     "client": {
         *         "id": 0,
         *         "sql": "select * from oil_send"
         *     }
         * }
         * response:
         *   {
         *     "data": {
         *         "msg": "success",
         *         "code": 0,
         *         "data": [
         *             {
         *                 "VOL": 30.11,
         *                 "Nzn": "001",
         *                 "Nozzle_St": "0",
         *                 "v_tot": "3623778."
         *             },
         *             {
         *                 "VOL": 30.94,
         *                 "Nzn": "002",
         *                 "Nozzle_St": "0",
         *                 "v_tot": "3680828."
         *             }
         *         ]
         *     },
         *     "message": "",
         *     "status": 200
         * }
         */
        routeConfig.put(CONTENT_PATH + "/client/generic/db/query", new GenericDbQueryController());

        /**
         * 通过mysql SQL语句查询数据库
         * request:
         *  {
         *     "username": "xuedianfu",
         *     "password": "123456",
         *     "deviceId": "d1",
         *     "client": {
         *         "id": 0,
         *         "sql": "select * from oil_send"
         *     }
         * }
         * response:
         *   {
         *     "data": {
         *         "msg": "success",
         *         "code": 0,
         *         "data": [
         *             {
         *                 "VOL": 30.11,
         *                 "Nzn": "001",
         *                 "Nozzle_St": "0",
         *                 "v_tot": "3623778."
         *             },
         *             {
         *                 "VOL": 30.94,
         *                 "Nzn": "002",
         *                 "Nozzle_St": "0",
         *                 "v_tot": "3680828."
         *             }
         *         ]
         *     },
         *     "message": "",
         *     "status": 200
         * }
         */
        routeConfig.put(CONTENT_PATH + "/client/mysql/query", new MySqlQueryController());
        routeConfig.put(CONTENT_PATH + "/client/control/query", new MySqlQueryController());

        /**
         * 通过mssql SQL语句查询数据库
         * request:
         *  {
         *     "username": "xuedianfu",
         *     "password": "123456",
         *     "deviceId": "d1",
         *     "client": {
         *         "id": 0,
         *         "sql": "sql": "select * from mytable1"
         *     }
         * }
         * response:
         *   {
         *     "data": {
         *         "msg": "success",
         *         "code": 0,
         *         "data": [
         *             {
         *                 "VOL": 30.11,
         *                 "Nzn": "001",
         *                 "Nozzle_St": "0",
         *                 "v_tot": "3623778."
         *             },
         *             {
         *                 "VOL": 30.94,
         *                 "Nzn": "002",
         *                 "Nozzle_St": "0",
         *                 "v_tot": "3680828."
         *             }
         *         ]
         *     },
         *     "message": "",
         *     "status": 200
         * }
         */
        routeConfig.put(CONTENT_PATH + "/client/mssql/query", new MssqlQueryController());

        /**
         * 通过oracle SQL语句查询数据库
         * request:
         *  {
         *     "username": "xuedianfu",
         *     "password": "123456",
         *     "deviceId": "d1",
         *     "client": {
         *         "id": 0,
         *         "sql": "select * from \"book\" b"
         *     }
         * }
         * response:
         *   {
         *     "data": {
         *         "msg": "success",
         *         "code": 0,
         *         "data": [
         *             {
         *                 "VOL": 30.11,
         *                 "Nzn": "001",
         *                 "Nozzle_St": "0",
         *                 "v_tot": "3623778."
         *             },
         *             {
         *                 "VOL": 30.94,
         *                 "Nzn": "002",
         *                 "Nozzle_St": "0",
         *                 "v_tot": "3680828."
         *             }
         *         ]
         *     },
         *     "message": "",
         *     "status": 200
         * }
         */
        routeConfig.put(CONTENT_PATH + "/client/oracle/query", new OracleQueryController());

        /**
         * com执行命令接口
         * request:
         *   {
         *     "username": "xuedianfu",
         *     "password": "123456",
         *     "deviceId": "d1",
         *     "client": {
         *         "id": 0,
         *         "command": "0169323031303003"
         *     }
         * }
         * response:
         *   {
         *     "status": 500,
         *     "message": "Programe exception",
         *     "data": "0169323031303003"
         * }
         */
        routeConfig.put(CONTENT_PATH + "/client/com/command", new ComCommandController());

        /**
         * udp执行命令接口
         * request:
         *   {
         *     "username": "xuedianfu",
         *     "password": "123456",
         *     "deviceId": "d1",
         *     "client": {
         *         "id": 0,
         *         "command": "0169323031303003"
         *     }
         * }
         * response:
         *   {
         *     "status": 500,
         *     "message": "Programe exception",
         *     "data": "0169323031303003"
         * }
         */
        routeConfig.put(CONTENT_PATH + "/client/udp/command", new UdpCommandController());

        /**
         * OPC执行命令接口
         * request:
         *   {
         *     "username": "xuedianfu",
         *     "password": "123456",
         *     "deviceId": "d1",
         *     "client": {
         *          "id": 0,
         *          "tags": ["xuedianfu.2022.arg", "xuedianfu.2022.name", "xuedianfu.2022.persion"]
         *          或
         *          "tags": [{"ns": 2, "tag": "xuedianfu.2022.arg", "isWrite": true, "value": 45}, {"ns": 2, "tag": "xuedianfu.2022.name"}, {"ns": 2, "tag": "xuedianfu.2022.persion"}]
         *          或
         *          "tags": [{"tag": "xuedianfu.2022.arg", "isWrite": true, "value": 45}, {"tag": "xuedianfu.2022.name"}]
         *     }
         * }
         * response:
         *   {
         *     "status": 500,
         *     "message": "Programe exception",
         *     "data": ""
         * }
         */
        routeConfig.put(CONTENT_PATH + "/client/opc/command", new OpcCommandController());

        /**
         * CAN执行命令接口
         * request:
         *   {
         *     "username": "xuedianfu",
         *     "password": "123456",
         *     "deviceId": "d1",
         *     "client": {
         *          "id": 0,
         *          "items": [
         *              {"tag": "abc", "canId": 1, "isWrite": false},
         *              {"tag": "tag2", "canId": 1, "isWrite": true, "value": 10}
         *          ]
         *     }
         * }
         * response:
         *   {
         *     "status": 500,
         *     "message": "Programe exception",
         *     "data": ""
         * }
         */
        routeConfig.put(CONTENT_PATH + "/client/can/command", new CanCommandController());

        /**
         * DNP执行命令接口
         * request:
         *   {
         *     "username": "xuedianfu",
         *     "password": "123456",
         *     "deviceId": "d1",
         *     "client": {
         *          "id": 0,
         *          "items": [
         *              {"tag": "abc", "canId": 1, "isWrite": false},
         *              {"tag": "tag2", "canId": 1, "isWrite": true, "value": 10}
         *          ]
         *     }
         * }
         * response:
         *   {
         *     "status": 500,
         *     "message": "Programe exception",
         *     "data": ""
         * }
         */
        routeConfig.put(CONTENT_PATH + "/client/dnp/command", new DnpCommandController());

        /**
         * bacnet执行命令接口
         * request:
         *   {
         *     "username": "xuedianfu",
         *     "password": "123456",
         *     "deviceId": "d1",
         *     "client": {
         *          "id": 0,
         *          "items": [
         *              {"tag": "tag0", "deviceId": 1, "property": 85, "datatype": 0, "instance": 0, "isWrite": true, "value": 1244},
         *              {"tag": "tag1", "deviceId": 1, "property": 85, "datatype": 0, "instance": 0}
         *          ]
         *     }
         * }
         * response:
         *   {
         *     "status": 500,
         *     "message": "Programe exception",
         *     "data": ""
         * }
         */
        routeConfig.put(CONTENT_PATH + "/client/bacnet/command", new BACNetCommandController());

        /**
         * iec执行命令接口
         * request:
         *   {
         *     "username": "xuedianfu",
         *     "password": "123456",
         *     "deviceId": "d1",
         *     "client": {
         *          "id": 0,
         *          "items": [
         *              {"tag": "abc", "canId": 1, "isWrite": false},
         *              {"tag": "tag2", "canId": 1, "isWrite": true, "value": 10}
         *          ]
         *     }
         * }
         * response:
         *   {
         *     "status": 500,
         *     "message": "Programe exception",
         *     "data": ""
         * }
         */
        routeConfig.put(CONTENT_PATH + "/client/iec/command", new IecCommandController());

        /**
         * MTConnect执行命令接口
         * request:
         *   {
         *     "username": "xuedianfu",
         *     "password": "123456",
         *     "deviceId": "d1",
         *     "client": {
         *          "id": 0,
         *          "items": [
         *              {"tag": "abc", "canId": 1, "isWrite": false},
         *              {"tag": "tag2", "canId": 1, "isWrite": true, "value": 10}
         *          ]
         *     }
         * }
         * response:
         *   {
         *     "status": 500,
         *     "message": "Programe exception",
         *     "data": ""
         * }
         */
        routeConfig.put(CONTENT_PATH + "/client/mtconnect/command", new MTConnectCommandController());

        /**
         * profibus执行命令接口
         * request:
         *   {
         *     "username": "xuedianfu",
         *     "password": "123456",
         *     "deviceId": "d1",
         *     "client": {
         *          "id": 0,
         *          "items": [
         *              {"tag": "abc", "function": 3, "slaveId": 1, "offset": 0, "datatype": 3, "isWrite": false},
         *              {"tag": "tag2", "function": 3, "slaveId": 1, "offset": 2, "datatype": 3, "isWrite": true, "value": 10}
         *          ]
         *     }
         * }
         * response:
         *   {
         *     "status": 500,
         *     "message": "Programe exception",
         *     "data": ""
         * }
         */
        routeConfig.put(CONTENT_PATH + "/client/profibus/command", new ProfibusCommandController());

        /**
         * profinet执行命令接口
         * request:
         *   {
         *     "username": "xuedianfu",
         *     "password": "123456",
         *     "deviceId": "d1",
         *     "client": {
         *          "id": 0,
         *          "items": [
         *              {"tag": "abc", "function": 3, "slaveId": 1, "offset": 0, "datatype": 3, "isWrite": false},
         *              {"tag": "tag2", "function": 3, "slaveId": 1, "offset": 2, "datatype": 3, "isWrite": true, "value": 10}
         *          ]
         *     }
         * }
         * response:
         *   {
         *     "status": 500,
         *     "message": "Programe exception",
         *     "data": ""
         * }
         */
        routeConfig.put(CONTENT_PATH + "/client/profinet/command", new ProfinetCommandController());

        /**
         * modbus执行命令接口
         * request:
         *   {
         *     "username": "xuedianfu",
         *     "password": "123456",
         *     "deviceId": "d1",
         *     "client": {
         *          "id": 0,
         *          "items": [
         *              {"tag": "abc", "function": 3, "slaveId": 1, "offset": 0, "datatype": 3, "isWrite": false},
         *              {"tag": "tag2", "function": 3, "slaveId": 1, "offset": 2, "datatype": 3, "isWrite": true, "value": 10}
         *          ]
         *     }
         * }
         * response:
         *   {
         *     "status": 500,
         *     "message": "Programe exception",
         *     "data": ""
         * }
         */
        routeConfig.put(CONTENT_PATH + "/client/modbus/command", new ModbusCommandController());

        /**
         * 系统执行命令接口
         * linux下系统升级命令：/usr/bin/bash /data/app/executer
         * request:
         *    {
         *     "username": "xuedianfu",
         *     "password": "123456",
         *     "deviceId": "d1",
         *     "command": "netstat -tnlp"
         *     或
         *     {"powershell": true, "cmd": "netstat -tnlp"}
         * }
         * response:
         *  {
         *     "data": "Active Internet connections (only servers)\nProto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    \ntcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1110/sshd           \ntcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1645/master         \ntcp6       0      0 :::22                   :::*                    LISTEN      1110/sshd           \ntcp6       0      0 ::1:25                  :::*                    LISTEN      1645/master         \n",
         *     "message": "",
         *     "status": 200
         * }
         */
        routeConfig.put(CONTENT_PATH + "/client/system/command", new SystemCommandController());

        /**
         * 执行http请求命令
         * request:
         *    {
         *     "username": "xuedianfu",
         *     "password": "123456",
         *     "deviceId": "d1",
         *     "command": {
         *         "method": "post",
         *         "protocol": "http",
         *         "url": "//www.abc.com/test/user",
         *         "headers": {"Content-Type": "application/json;charset=utf-8", "token": "dfidsf8ewrjf7df8"},
         *         "requestBody": "a=aa&b=bb&c=cc"
         *     }
         * }
         * response:
         *  {
         *     "data": "",
         *     "message": "",
         *     "status": 200
         * }
         */
        routeConfig.put(CONTENT_PATH + "/client/http/command", new HttpCommandController());

        /**
         * 获取推送数据接口
         * request:
         *   {
         *     "username": "xuedianfu",
         *     "password": "123456",
         *     "deviceId": "d1",
         *     "client": {
         *          "id": 0
         *     }
         * }
         * response:
         *   {
         *     "status": 500,
         *     "message": "Programe exception",
         *     "data": ""
         * }
         */
        routeConfig.put(CONTENT_PATH + "/client/pushData/get", new PushDataController());

        /**
         * 执行关闭客户端命令
         * request:
         *    {
         *     "username": "xuedianfu",
         *     "password": "123456",
         *     "deviceId": "d1",
         *     "client": {
         *          "isExceptionExit": true,
         *          "amount": 10
         *      }
         * }
         * response:
         *  {
         *     "data": "",
         *     "message": "",
         *     "status": 200
         * }
         */
        routeConfig.put(CONTENT_PATH + "/client/shutdown", new ShutdownClientController());

        /**
         * 查看客户端版本号
         * request:
         *    {
         *     "username": "xuedianfu",
         *     "password": "123456",
         *     "deviceId": "d1"
         * }
         * response:
         *  {
         *     "data": "2",
         *     "message": "",
         *     "status": 200
         * }
         */
        routeConfig.put(CONTENT_PATH + "/client/view/version", new ViewClientVersionController());

        /**
         * 查看客户端信息
         * request:
         *    {
         *     "username": "xuedianfu",
         *     "password": "123456",
         *     "deviceId": "d1"
         * }
         * response:
         *  {
         *     "data": "2",
         *     "message": "",
         *     "status": 200
         * }
         */
        routeConfig.put(CONTENT_PATH + "/client/view/infomation", new ClientInformationController());

        return routeConfig;
    }
}
